package com.icss.lesson4;

public class TestMain2 {
    public static void main(String[] args) {
        new Thread("线程1") {

            @Override
            public  void run() {
                for (int i = 0; i < 100; i++) {
                    if (i == 99) {
                        Thread t2 = new Thread("线程2") {

                            @Override
                            public void run() {
                                for (int i = 0; i < 100; i++) {
                                    if (i == 99) Thread.yield();
                                    System.out.println(Thread.currentThread() + "@" + i);
                                }
                            }
                        };
                        t2.start();
                        try {
                            t2.join();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println(Thread.currentThread() + "@" + i);
                }
            }
        }.start();

//
//        new Thread("线程3") {
//
//            @Override
//            public void run() {
//                for (int i = 0; i < 100; i++) {
//                    if (i == 99) Thread.yield();
//                    System.out.println(Thread.currentThread() + "@" + i);
//                }
//            }
//        }.start();
    }
}
